<?php
namespace core\tv\model;

use core\Model;
use core\tv\model\VideoModel;

class VideoSourceModel extends Model
{

    /**
     * 去前缀表名
     *
     * @var unknown
     */
    protected $name = 'tv_video_source';

    /**
     * 自动写入时间戳
     *
     * @var unknown
     */
    protected $autoWriteTimestamp = true;

    /**
     * 别名查询
     *
     * @return \think\db\Query
     */
    protected function aliasQuery()
    {
        return $this->alias('vs');
    }

    /**
     * 链接视频
     *
     * @return \think\db\Query
     */
    public function withVideo()
    {
        $query = $this->aliasQuery();
        return $this->joinVideo($query);
    }

    /**
     * 链接视频
     *
     * @return \think\db\Query
     */
    protected function joinVideo($query)
    {
        return $query->join(VideoModel::getInstance()->getTableShortName() . ' v', 'v.id = vs.video_id');
    }

}